﻿using System;
using System.Windows.Forms;
using Origami.Data.Provider;
using SmsEntity;

namespace SmsRepository
{
    /// <summary>
    /// DataAccess
    /// </summary>
    public class DataAccess
    {
        /// <summary>
        /// GetDataSource
        /// </summary>
        /// <returns></returns>
        protected static DataSource GetDataSource(string sApplicationId)
        {
            try
            {
                DataSource ds = null;
                using (var xml = new XmlConfiguration(new DBLogonInfo(sApplicationId)))
                {
                    if (xml.Read())
                        ds = new DataSource
                                 {
                                     Provider = xml.DBLogonInfo.Provider,
                                     ConnectionString = xml.DBLogonInfo.ConnectionString
                                 };
                }
                return ds;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, @"Error!",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }
        }
    }
}